
.MODEL tiny
.386

_TEXT SEGMENT USE16

ORG 7C00h

SECOND_BIN_SEGMENT	equ 9000h
SECOND_BIN_SIZE		equ	0A800h

start:

;
; jmp to main
;

	db 0EAh
	dw main, 0

main:
	cli
	
	;
	; initialize
	;
	
	xor     ax, ax
	xor 	bp, bp
	mov     ss, ax 
	mov     ds, ax
	mov     sp, 7c00h

	sti
	
	;
	; zero memory
	;
	
	mov ax, SECOND_BIN_SEGMENT
	mov	es, ax
	
	xor al, al
	xor di, di
	mov cx, 200h
	cld
	rep stosb
	
	;
	; read the second sector
	;
	
	mov al, 1
	mov cl, 2 ;the second sector
	xor bx, bx
	call read_sectors
	
	;
	; go to 0x9000:0
	;
	
	cli
	mov ax, es
	mov ds, ax
	mov ss, ax
	mov sp, SECOND_BIN_SIZE
	sti
	
	push es
	push 0
	
	retf
	
print:
	xor bx, bx
	mov ah, 0eh
	cld
	
@@:	lodsb
	test al, al
	jz print_end
	
	int 10h
	jmp @B
print_end:
	ret
	
read_sectors:
	mov ch, 0           ; Cylinder
	mov dh, 0           ; Head
						; DL = drive number passed from BIOS
	mov ah, 2
	int 13h
	jnc read_ok
	
	lea si, disk_error_msg
	call print
read_ok:
	ret
	
disk_error_msg			db 'Disk error', 13, 10, 7, 0
end_msg					db 'the end', 13, 10, 7, 0
ORG 7C00h + 510
dw 0AA55h

_TEXT ENDS
END start	
	
	
	
	
	
	
	
	
	
	
	
	
	
